package com.msda.controller;


import com.msda.pojo.dto.PageDTO;
import com.msda.pojo.dto.order.AuditCancellationDTO;
import com.msda.pojo.dto.order.AuditReservationDTO;
import com.msda.pojo.dto.room.RoomDTO;
import com.msda.pojo.entity.order.Cancellation;
import com.msda.pojo.entity.order.Order;
import com.msda.pojo.entity.order.Reservation;
import com.msda.pojo.entity.requirement.NoticeMessage;
import com.msda.pojo.vo.ReservationVO;
import com.msda.service.room.OrderService;
import com.msda.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/order")
@Validated
@Tag(name = "订单", description = "对订单进行操作")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Operation(summary = "提交订单")
    @PostMapping("/submit_order")
    public Result<String> submitOrder(@RequestBody Order order){
        return Result.success(orderService.submitOrder(order));
    }


    @Operation(summary = "根据Id获得订单")
    @PostMapping("/get_order_by_id/{orderId}")
    public Result<Order> getOrderById(@PathVariable String orderId){
        return Result.success(orderService.getOrderById(orderId));
    }

    @Operation(summary = "根据Id获得预订单")
    @PostMapping("/get_reservation_by_id/{reservationId}")
    public Result<Reservation> getReservationById(@PathVariable String reservationId){
        return Result.success(orderService.getReservationById(reservationId));
    }

    @Operation(summary = "根据Id获得取消订单表消息")
    @PostMapping("/get_cancellation_by_id/{cancellationId}")
    public Result<Cancellation> getCancellationById(@PathVariable String cancellationId){
        return Result.success(orderService.getCancellationById(cancellationId));
    }

    @Operation(summary = "取消订单")
    @PostMapping("/cancel_order/{orderId}")
    public Result<?> deleteOrder(@PathVariable String orderId){
        return Result.success(orderService.cancelOrder(orderId));
    }


//    待判断是否做
//    @Operation(summary = "更新订单")
//    @PostMapping("/update_order")
//    public Result<Order> updateRoom(@RequestBody Order order) throws DataFormatException {
//        return Result.success(orderService.updateOeder(order));
//    }


    @Operation(summary = "提交取消预订单表单")
    @PostMapping("/submit_cancel_reservation")
    public Result<String> submitCancelReservation(@RequestBody Cancellation cancellation){
        return Result.success(orderService.submitCancelReservation(cancellation));
    }

    @Operation(summary = "员工审核预订单")
    @PostMapping("/audit_reservation")
    public Result<?> auditReservation(@RequestBody AuditReservationDTO auditReservationDTO) {
        return Result.success(orderService.auditReservation(auditReservationDTO));
    }

    @Operation(summary = "员工审核取消订单表")
    @PostMapping("/audit_cancellation")
    public Result<?> auditCancellation(@RequestBody AuditCancellationDTO auditCancellationDTO) {
        return Result.success(orderService.auditCancellation(auditCancellationDTO));
    }

    @Operation(summary = "根据状态获取所有订单条数")
    @PostMapping("/get_all_order_Count/{status}")
    public Result<Long> getAllOrderCount(@PathVariable int status) {
        return Result.success(orderService.getAllOrderCount(status));
    }

    @Operation(summary = "根据状态分页获取订单信息")
    @PostMapping("/get_page_order/{status}")
    public Result<List<Order>> getPageRoom(@PathVariable int status,@RequestBody PageDTO pageDTO) {
        return Result.success(orderService.getPageOrder(status,pageDTO));
    }

    @Operation(summary = "根据状态获取所有预订单条数")
    @PostMapping("/get_all_reservation_Count/{status}")
    public Result<Long> getAllReservationCount(@PathVariable int status) {
        return Result.success(orderService.getAllReservationCount(status));
    }

    @Operation(summary = "根据状态分页获取预订单信息")
    @PostMapping("/get_page_reservation/{status}")
    public Result<List<Reservation>> getPageReservation(@PathVariable int status,@RequestBody PageDTO pageDTO) {
        return Result.success(orderService.getPageReservation(status,pageDTO));
    }

    @Operation(summary = "根据状态获取所有取消订单表条数")
    @PostMapping("/get_all_cancellation_Count/{status}")
    public Result<Long> getAllCancellationCount(@PathVariable int status) {
        return Result.success(orderService.getAllCancellationCount(status));
    }

    @Operation(summary = "根据状态获取所有取消订单表")
    @PostMapping("/get_page_cancellation/{status}")
    public Result<List<Cancellation>> getPageCancellation(@PathVariable int status,@RequestBody PageDTO pageDTO) {
        return Result.success(orderService.getPageCancellation(status,pageDTO));
    }

    @Operation(summary = "支付订单操作")
    @PostMapping("/pay_order/{orderId}")
    public Result<String> payOrder(@PathVariable String orderId) throws IllegalAccessException {
        return Result.success(orderService.payOrder(orderId));
    }

    @Operation(summary = "获得用户未支付订单")
    @PostMapping("/get_unpaid_order/{customerId}")
    public Result<Order> getUnpaidOrder(@PathVariable String customerId) throws IllegalAccessException {
        return Result.success(orderService.getUnpaidOrder(customerId));
    }

    @Operation(summary = "通知预订单与取消订单接口")
    @PostMapping("/notice_reservation_cancellation")
    public Result<List<NoticeMessage>> noticeMessage(){
        return Result.success(orderService.noticeMessage());
    }

    @Operation(summary = "根据id设置消息是否已读或未读")
    @PostMapping("/set_message_readStatus/{id}/{readStatus}")
    public Result<?> setMessageReadStatus(@PathVariable String id,@PathVariable boolean readStatus){
        return Result.success(orderService.setMessageReadStatus(id,readStatus));
    }

    @Operation(summary = "将全部消息设置为已读或者未读")
    @PostMapping("/set_all_message_readStatus/{readStatus}")
    public Result<?> setAllMessageReadStatus(@PathVariable boolean readStatus){
        return Result.success(orderService.setAllMessageReadStatus(readStatus));
    }

    @Operation(summary = "根据id查找消息")
    @PostMapping("/get_message_byId/{id}")
    public Result<NoticeMessage> getMessageReadStatus(@PathVariable String id){
        return Result.success(orderService.getMessageReadStatus(id));
    }


    @Operation(summary = "分页获得所有消息条数")
    @PostMapping("/get_all_message_Count")
    public Result<Long> getAllMessageCount() {
        return Result.success(orderService.getAllMessageCount());
    }

    @Operation(summary = "分页获取消息")
    @PostMapping("/get_page_message")
    public Result<List<NoticeMessage>> getPageMessage(@RequestBody PageDTO pageDTO) {
        return Result.success(orderService.getPageMessage(pageDTO));
    }

    @Operation(summary = "根据用户ID分页获取未支付或失效的订单")
    @PostMapping("/get_page_incomplete_order/{customerId}")
    public Result<List<Order>> getPageMessage(@PathVariable String customerId,@RequestBody PageDTO pageDTO) {
        return Result.success(orderService.getPageIncompleteOrder(customerId,pageDTO));
    }

    @Operation(summary = "根据用户ID分页获取预订单")
    @PostMapping("/get_page_reservation_byCustomerId/{customerId}")
    public Result<List<Reservation>> getPageReservationByCustomerId(@PathVariable String customerId,@RequestBody PageDTO pageDTO) {
        return Result.success(orderService.getPageReservationByCustomerId(customerId,pageDTO));
    }

    @Operation(summary = "员工删除预订单级联删除订单")
    @PostMapping("/staff_delete_reservation/{reservationId}")
    public Result<?> staffDeleteReservation(@PathVariable String reservationId) {
        return Result.success(orderService.staffDeleteReservation(reservationId));
    }

    @Operation(summary = "客户查询全部已过期订单")
    @PostMapping("/customer_getOrder_expired/{customerId}")
    public Result<?> customerGetOrderExpired(@PathVariable String customerId) {
        return Result.success(orderService.customerGetOrderExpired(customerId));
    }

    @Operation(summary = "客户删除已过期的订单")
    @PostMapping("/customer_deleteOrder_expired/{customerId}")
    public Result<?> customerDeleteOrderExpired(@PathVariable String customerId) {
        return Result.success(orderService.customerDeleteOrderExpired(customerId));
    }

    @Operation(summary = "根据预订单id获得关联预订单的具体内容")
    @PostMapping("/getReservation_relate_detail/{reservationId}")
    public Result<ReservationVO> getReservationRelateDetail(@PathVariable String reservationId) {
        return Result.success(orderService.getReservationRelateDetail(reservationId));
    }




//    @Operation(summary = "测试消息队列")
//    @PostMapping("/rabbitMQ")
//    public Result<Integer> auditReservation() {
//        return Result.success(orderService.testRabbitMQ());
//    }


}
